package com.example.administrator.uis.view.paintView

import android.content.Context
import android.graphics.*
import android.util.AttributeSet
import android.view.View
import com.example.administrator.uis.R

/**
 * Created by Administrator on 2017/11/14 0014.
 */
class Practice08XfermodeView(context: Context?, attrs: AttributeSet?) : View(context, attrs) {
    var paint = Paint(Paint.ANTI_ALIAS_FLAG)
    var bitmapdown = BitmapFactory.decodeResource(resources, R.drawable.batman)
    var bitmap2 = BitmapFactory.decodeResource(resources, R.drawable.batman_logo)
    var xfermode1=PorterDuffXfermode(PorterDuff.Mode.SRC)
    var xfermode2=PorterDuffXfermode(PorterDuff.Mode.DST_OUT)
    var xfermode3=PorterDuffXfermode(PorterDuff.Mode.DST_IN)
    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        var saved=canvas?.saveLayer(null,null ,Canvas.ALL_SAVE_FLAG)
        canvas?.drawBitmap(bitmapdown,0f,0f,paint)
        paint.xfermode = xfermode3
        canvas?.drawBitmap(bitmap2,400f,400f,paint)
        paint.xfermode = null
        canvas?.restoreToCount(saved!!)

      /*  paint.color=Color.YELLOW
        canvas?.drawRect(0f,0f,200f,200f,paint)
        paint.xfermode = xfermode1
        paint.color=Color.GREEN
        canvas?.drawCircle(200f,200f,100f,paint)
        paint.xfermode=null
        canvas?.restore()*/
    }
}